package com.lz.service.smsmail;

import org.apache.commons.lang.exception.ExceptionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;

/**
 * 应用启动入口类
 * @author likejian
 *
 */
@SpringBootApplication
@EnableEurekaClient
@EnableFeignClients
@EnableCircuitBreaker
public class Main {

	private final static Logger LOG = LoggerFactory.getLogger(Main.class);
	
	@Bean
	public RestTemplate restTemplate(){
		return new RestTemplate();
	}
	
	public static void main(String[] args) throws Exception {
		LOG.info("=====开始启动=====");
		SpringApplication.run(Main.class, args);
		Init.init();
		Thread shutdownHook = new Thread() {  
            public void run() {  
            	LOG.info("===========shutdownHook...============");  
            	try {
					Init.destroy();
				} catch (Exception e) {
					e.printStackTrace();
					LOG.error("Exception={}", ExceptionUtils.getFullStackTrace(e));
				}	
            }  
        };  
        Runtime.getRuntime().addShutdownHook(shutdownHook);  
		LOG.info("=====启动完成=====");
	}
}
